package IO;

import org.junit.Test;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

/**
 *
 */
public class FileInputOutputStream {
    //字节流读写图片、视频文件,读取中文会乱码,但是可以复制文本类文件
    @Test
    public void test(){
        FileInputStream fis = null;
        FileOutputStream fos=null;
        try {
            fis = new FileInputStream(new File("user2.dat"));
            fos = new FileOutputStream(new File("user2.dat"));
            int len;
            byte[] bytes=new byte[1024];
            while ((len=fis.read(bytes))!=-1){
//                String s = new String(bytes, 0, len);
//                System.out.println(s);
                fos.write(bytes,0,len);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            try {
                fis.close();
                fos.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}